<html>
<head><meta charset="utf-8"><title>Size &gt;= Alignment for non-ZSTs · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html">Size &gt;= Alignment for non-ZSTs</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="169500209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169500209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169500209">(Jul 02 2019 at 17:22)</a>:</h4>
<p>We don't have any general layout rules that hold for all types. But AFAICT for all non-ZSTs, Size &gt;= Alignment.</p>



<a name="169500226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169500226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169500226">(Jul 02 2019 at 17:23)</a>:</h4>
<p>Shall we document this somewhere ?</p>



<a name="169500281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169500281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169500281">(Jul 02 2019 at 17:23)</a>:</h4>
<p>We should also probably document for each of the possible ZSTs that their alignment &gt;= size.</p>



<a name="169500671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169500671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169500671">(Jul 02 2019 at 17:27)</a>:</h4>
<p>The formulation that doesn't need special casing for ZSTs is that "size has to be a multiple of alignment". Which is currently true but trying to document it riles up the "size vs stride" discussion again...</p>



<a name="169502225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169502225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169502225">(Jul 02 2019 at 17:45)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> that sounds good - we can add a note, explaining some of the straightforward consequences of that.</p>



<a name="169502275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169502275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169502275">(Jul 02 2019 at 17:45)</a>:</h4>
<p>I'm not sure where, but the beginning of the layout section might be appropriate</p>



<a name="169502364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169502364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169502364">(Jul 02 2019 at 17:46)</a>:</h4>
<p>or the glossary</p>



<a name="169502379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169502379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169502379">(Jul 02 2019 at 17:46)</a>:</h4>
<p>we can define <code>size</code> and <code>alignment</code> there</p>



<a name="169504517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169504517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169504517">(Jul 02 2019 at 18:06)</a>:</h4>
<p>as long as we keep the reading from the array section, that we might want to change this to support stride&gt;size types</p>



<a name="169504522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169504522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169504522">(Jul 02 2019 at 18:06)</a>:</h4>
<p>until the lang team tells us "no"^^</p>



<a name="169504542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169504542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169504542">(Jul 02 2019 at 18:06)</a>:</h4>
<p>this is one of the things I think Rust should have done pre-1.0 :/</p>



<a name="169504820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169504820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169504820">(Jul 02 2019 at 18:10)</a>:</h4>
<p>I can't really imagine us ever actually doing this change now that we're years past 1.0, but <em>long sigh</em> yeah, in the terminology of the array chapter, it's "stride is a multiple of alignment"</p>



<a name="169506192"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169506192" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169506192">(Jul 02 2019 at 18:24)</a>:</h4>
<p>well if I am the only one who thinks it is worthwhile to keep that option open, I am fine being outvoted</p>



<a name="169506250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169506250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169506250">(Jul 02 2019 at 18:24)</a>:</h4>
<p>it's not like this is <em>so</em> close to my heart. we are not talking about union semantics after all. :P</p>



<a name="169508656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169508656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169508656">(Jul 02 2019 at 18:51)</a>:</h4>
<p>I would prefer to have a stride, and I'll also would prefer to somehow be able to reuse trailing padding.</p>



<a name="169508753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169508753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169508753">(Jul 02 2019 at 18:52)</a>:</h4>
<p>I don't know what Swift does here</p>



<a name="169798674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size%20%3E%3D%20Alignment%20for%20non-ZSTs/near/169798674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Size.20.3E.3D.20Alignment.20for.20non-ZSTs.html#169798674">(Jul 07 2019 at 06:34)</a>:</h4>
<p>given the existence of unsafe code that assumes that stride = size, it's unlikely that we'd ever have the ability to change it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>